// 导航守卫
import router from './router'
import store from './store'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'

const pageArr = ['/404', '/login']
// 前置守卫
router.beforeEach(async(to, from, next) => {
  Nprogress.start()
  if (store.getters.token) {
    if (to.path.toLowerCase() === '/login') {
      next('/')
    } else {
      // await store.dispatch('user/getUserInfo')
      // next(to.fullPath)
      next()
    }
  } else {
    if (pageArr.includes(to.path.toLowerCase())) {
      next()
    } else {
      next(`/login?redirect=${encodeURIComponent(to.fullPath)}`)
    }
  }
  Nprogress.done()
})

// 后置守卫
